package com.gin.kotlin.vegetables_kot.base

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import com.gin.kotlin.vegetables_kot.app.App


/**
 * 输入法工具类
 */
class InputMethodUtils {
    companion object {

        /**
         * 获取输入法管理器
         * @param context Context
         * @return [InputMethodManager]
         */
        fun getManager(context: Context = App.INSTANCE) = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

        /**
         * 激活输入法
         * @param view 需要激活输入法的View，一般为EditText
         * @param context Context
         * @return Boolean
         */
        fun show(view: View, context: Context = App.INSTANCE) = getManager(context).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)

        /**
         * 关闭输入法
         * @param view 已激活输入法的View
         * @param context Context
         * @return Boolean
         */
        fun hide(view: View, context: Context = App.INSTANCE) = getManager(context).hideSoftInputFromWindow(view.windowToken, 0)
    }
}